#ifndef FRAMELESSWINDOW_H
#define FRAMELESSWINDOW_H

#include <QMainWindow>

class  FramelessWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit FramelessWindow(QWidget *parent = nullptr);

    void setResizeable(bool resizeable = true);
    bool isResizeable() { return _resizable; }
    void setResizeableAreaWidth(int width = 5);

    void setContentsMargins(const QMargins &margins);
    void setContentsMargins(int left, int top, int right, int bottom);
    QMargins contentsMargins() const;
    QRect contentsRect() const;
    void getContentsMargins(int *left, int *top, int *right, int *bottom) const;

public Q_SLOTS:
    void showFullScreen();

protected:
    void setTitleBar(QWidget* titleBar);
    void addIgnoreWidget(QWidget* widget);
    void showEvent(QShowEvent *event) override;
    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;

private Q_SLOTS:
    void onTitleBarDestroyed();

private:
    long getResizeRegion(int x, int y, int borderWidth);
    void moveToCenter();

    bool _resizable;
    bool _justMaximized;

    QWidget* _titleBar;
    QList<QWidget*> _whiteList;
    int _borderWidth;
    QMargins _margins;
    QMargins _frames;

};

#endif // FRAMELESSWINDOW_H
